Eloi.shift   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 23
rs 9.2833
c 0
b 0
f 0
cc 5
1
export class Eloi {
2
    constructor(OriginalDate = Date, { global = true } = {}) {
3
        this._OriginalDate = OriginalDate;
4
        this._setGlobal = global;
5
    }
6
7
    shift(offsetMs) {
8
        const OriginalDate = this._OriginalDate;
0 ignored issues
show
Unused Code introduced by
The constant OriginalDate seems to be never used. Consider removing it.
Loading history...
9
10
        this._EloiDate = class extends OriginalDate {
11
            constructor(...args) {
12
                if (args.length === 0) {
13
                    super(OriginalDate.now() + offsetMs);
0 ignored issues
show
Bug introduced by
The variable OriginalDate seems to be never declared. If this is a global, consider adding a /** global: OriginalDate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
                } else {
15
                    super(...args);
16
                }
17
            }
18
19
            static now() {
20
                return OriginalDate.now() + offsetMs;
0 ignored issues
show
Bug introduced by
The variable OriginalDate seems to be never declared. If this is a global, consider adding a /** global: OriginalDate */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
21
            }
22
        };
23
24
        if (this._setGlobal) {
25
            global.Date = this._EloiDate;
26
        }
27
28
        return this._EloiDate;
29
    }
30
31
    reset() {
32
        if (this._setGlobal) {
33
            global.Date = this._OriginalDate;
34
        }
35
    }
36
}
37
38
export default new Eloi();
39